﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace 数组程序设计
{
    internal class Program
    {
        static void Main(string[] args)
        {
            //静态初始化案例
            //已知班级学生成绩为{100 99 88 97},请计算平均分

            int[] newInt = { 100, 99, 88, 97 };

            int newSum = 0;

            for (int i = 0; i < newInt.Length; i++)
            {
                newSum = newSum + newInt[i];
            }

            Console.WriteLine("四位学生的平均分为：" + newSum / newInt.Length);

            //动态初始化案例
            //全班共有五个学生，请键盘录入每个人成绩，计算平均分

            int[] ints = new int[5];

            int sum = 0;
            
            //获取用户输入的五个成绩
            for(int i = 0; i < ints.Length; i++)
            {
                Console.WriteLine("请输入第{0}个成绩:",i + 1);
                ints[i] = Convert.ToInt32(Console.ReadLine());

            }

            for (int i = 0;i < ints.Length;i++)
            {
                sum = sum + ints[i];
            }
            Console.WriteLine(sum / ints.Length);

            Console.Read();
        }
    }
}
